package com.guigu.basedservice.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.basedservice.dto.MaintenanceTypeDto;
import com.guigu.basedservice.entity.BaseMaintainTypeServ;
import com.guigu.basedservice.service.BaseMaintainTypeServService;
import com.guigu.basedservice.service.MaintenanceTypeService;
import com.guigu.basedservice.vo.MaintenanceTypeVo;
import com.guigu.commonutils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author heyuhang
 * @create 2024/9/25
 */
@CrossOrigin
@RestController
@RequestMapping("/basedservice/maintenance-type")
public class MaintenanceTypeController {

    @Autowired(required = false)
    private MaintenanceTypeService maintenanceTypeService;

    @Autowired(required = false)
    private BaseMaintainTypeServService baseMaintainTypeServService;

    @RequestMapping("/getMaintenanceType/{currentPage}/{pageSize}")
    public PageInfo<MaintenanceTypeDto> getMaintenanceType(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody MaintenanceTypeVo vo
    ){
        System.out.println("MaintenanceTypeVo++++"+vo);
        PageInfo<MaintenanceTypeDto> maintenanceType = maintenanceTypeService.getMaintenanceType(currentPage,pageSize,vo);
        return maintenanceType;
    }

    @ApiOperation("获取单个BaseMaintainTypeServ数据")
    @RequestMapping("/getOne/{id}")
    public BaseMaintainTypeServ getOne(@PathVariable String id){
        return baseMaintainTypeServService.getById(id);
    }

    @ApiOperation("获取单个BaseMaintainTypeServ数据")
    @RequestMapping("/getOne2/{id}")
    public MaintenanceTypeDto getOne2(@PathVariable String id){
        return maintenanceTypeService.getOne2(id);
    }

    @ApiOperation("修改BaseMaintainTypeServ数据")
    @RequestMapping("/update")
    public Boolean update(@RequestBody BaseMaintainTypeServ baseMaintainTypeServ){
        System.out.println("baseMaintainTypeServ++++"+baseMaintainTypeServ);
        boolean b = baseMaintainTypeServService.updateById(baseMaintainTypeServ);
        return b;
    }

    @ApiOperation("删除BaseMaintainTypeServ数据")
    @RequestMapping("/delete/{mtsUuid}")
    public Boolean delete(@PathVariable String mtsUuid){
        return baseMaintainTypeServService.removeById(mtsUuid);
    }

    @ApiOperation("查询所有BaseMaintainTypeServ数据")
    @RequestMapping("/list")
    public R list() {
        List<BaseMaintainTypeServ> baseMaintainTypeServList = baseMaintainTypeServService.list(null);
        return R.ok().data("baseMaintainTypeServList", baseMaintainTypeServList);
    }

    @ApiOperation("添加MaintenanceTypeDto数据")
    @PostMapping("/addMaintenanceTypeDto")
    public Boolean addMaintenanceTypeDto(@RequestBody MaintenanceTypeDto maintenanceTypeDto){
        System.out.println("maintenanceTypeDto9999++++"+maintenanceTypeDto);
        BaseMaintainTypeServ baseMaintainTypeServ = new BaseMaintainTypeServ();
        baseMaintainTypeServ.setCatalogUuid(maintenanceTypeDto.getCatalogUuid());

        baseMaintainTypeServ.setMaintainType(maintenanceTypeDto.getMaintainType());
        baseMaintainTypeServ.setVersion(BigDecimal.valueOf(0));
        baseMaintainTypeServService.save(baseMaintainTypeServ);
        return true;
    }

}
